<template>
	<view class="bg-white box">
		<view class="nav-box ">
			 
			<u-tabs :list="cateTypeList" @click="tabClick" :scrollable='true' lineWidth='30rpx' :current='tabIndedx' lineHeight='4rpx' lineColor='#000' :activeStyle="{  color: '#000',   fontSize :'28rpx',  fontWeight: 'bold', }"></u-tabs>
		</view>
		<view class="line"></view>
		<view class="bg-white padding-25">
			<homeCareList :careList="careList" @reservation="reservation" @goDetails='goDetails'></homeCareList>
		</view>
	</view>
</template>

<script>
	import homeCareList from '@/components/homeCare/list.vue'
	import {
		cateList
	} from "@/api/culturalPropaganda";
    import {serviceDetail,nurseList} from '@/api/homeCare'
	export default {
		components: {
			homeCareList
		},
		data() {
			return {
				 list1: [{
				                    name: '关注',
				                }, {
				                    name: '推荐',
				                }, {
				                    name: '电影'
				                }, {
				                    name: '科技'
				                }, {
				                    name: '音乐'
				                }, {
				                    name: '美食'
				                }, {
				                    name: '文化'
				                }, {
				                    name: '财经'
				                }, {
				                    name: '手工'
				                }],
				tabIndedx: 0,
				careList: [ ],
				cateTypeList: [],
                id:'',
                page:1,
                tabId:'',
                tag:'',
                isMore:true
			}
		},
		onLoad(e) {
            this.id = e.id
			this.getCateList()
		},
        //上拉加载函数
        onReachBottom(){
            if(this.isMore){
                setTimeout(()=>{
                    this.serviceDetail()
                },100)
            }else{
                uni.showToast({
                    title: '暂无更多',
                    icon: 'none'
                })
            }

        },
        onPullDownRefresh () {
            //刷新初始化数据
            this.init()
            //关闭刷新动画
            setTimeout(function () {
                uni.stopPullDownRefresh()
            }, 1000)
        },
		methods: {
            init(){
                this.page = 1
                this.careList = []
                this.serviceDetail()
            },
			getCateList() {
				cateList({
					type: 1
				}).then(res => {
					if (res.code == 1) {
						this.cateTypeList = res.data
                        this.tabIndedx =0
                        if(this.id){
                            this.cateTypeList.map((item,index)=>{
                                if (item.id == this.id){
                                    this.tabIndedx =index
                                }
                            })
                        }
                        this.tabId= res.data[this.tabIndedx].id
                        this.tag = res.data[this.tabIndedx].name
                        this.init()
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			tabClick(e) {
                this.tabId =e.id
                this.tag =e.name
                this.init()
			},
            serviceDetail(){
                let data = {
                    tag:this.tag,
                    page:this.page ,
                    limit:10
                },arr =[]
                nurseList(data).then(res=>{
                    if (res.code == 1){
                        arr= res.data
                        arr.map(item =>{
                            var type = item.tags.split(",");
                            item.type = type
                        })
                        this.careList = this.careList.concat(arr)
                        if (res.data.length < 10){
                            this.isMore = false
                        }else {
                            this.isMore = true
                            this.page ++

                        }
                    }else{
                        uni.showToast({
                            title: res.msg,
                            icon: 'none'
                        })
                    }
                })

            },
			goDetails(e) {
				uni.navigateTo({
					url: "/pageA/homeCare/details"
				})
			},
			reservation(e) {
				uni.navigateTo({
					url: '/pageA/homeCare/reservation'
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.nav-box {
		position: relative;

		 
	}

	.line {
		height: 20rpx;
		background: #F7F7F7;
	}
</style>